import { defineStore } from 'pinia'
import { ref } from 'vue'

// 定义 Store
export const useLoginStore = defineStore(
  'login',
  () => {
    // 登录信息
    const TokenStatus = ref<boolean>(true)

    // 保存登录状态
    const setTokenStatus = (val: any) => {
        TokenStatus.value = val
    }

    return {
        TokenStatus,
        setTokenStatus,
    }
  },
  // TODO: 持久化
  {
    persist: {
      // 调整为兼容多端的API
      storage: {
        setItem(key, value) {
          uni.setStorageSync(key, value)
        },
        getItem(key) {
          return uni.getStorageSync(key)
        },
      },
    },
  },
)
